<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="用户" prop="customerId">
									<el-input v-model="form.customerId" placeholder="请输入用户" clearable></el-input>
								</el-form-item>
								<el-form-item label="部门/分店" prop="departmentId">
									<el-input v-model="form.departmentId" placeholder="请输入部门/分店" clearable></el-input>
								</el-form-item>
								<el-form-item label="区域全路径" prop="regionPath">
									<el-input v-model="form.regionPath" placeholder="请输入区域全路径" clearable></el-input>
								</el-form-item>
								<el-form-item label="会员等级" prop="membershipLevel">
									<el-input v-model="form.membershipLevel" placeholder="请输入会员等级" clearable></el-input>
								</el-form-item>
								<el-form-item label="域名后缀" prop="urlName">
									<el-input v-model="form.urlName" placeholder="请输入域名后缀" clearable></el-input>
								</el-form-item>
								<el-form-item label="登录账号" prop="loginName">
									<el-input v-model="form.loginName" placeholder="请输入登录账号" clearable></el-input>
								</el-form-item>
								<el-form-item label="密码" prop="password">
									<el-input v-model="form.password" placeholder="请输入密码" clearable></el-input>
								</el-form-item>
								<el-form-item label="姓名" prop="userName">
									<el-input v-model="form.userName" placeholder="请输入姓名" clearable></el-input>
								</el-form-item>
								<el-form-item label="电话" prop="telephone">
									<el-input v-model="form.telephone" placeholder="请输入电话" clearable></el-input>
								</el-form-item>
								<el-form-item label="地址" prop="address">
									<el-input v-model="form.address" placeholder="请输入地址" clearable></el-input>
								</el-form-item>
								<el-form-item label="邮箱" prop="email">
									<el-input v-model="form.email" placeholder="请输入邮箱" clearable></el-input>
								</el-form-item>
								<el-form-item label="1激活 0失效" prop="status">
									<el-input v-model="form.status" placeholder="请输入1激活 0失效" clearable></el-input>
								</el-form-item>
								<el-form-item label="最后登录时间" prop="lastInTime">
									<el-input v-model="form.lastInTime" placeholder="请输入最后登录时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="创建时间" prop="createTime">
									<el-input v-model="form.createTime" placeholder="请输入创建时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="最后续费时间" prop="lastPayTime">
									<el-input v-model="form.lastPayTime" placeholder="请输入最后续费时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="注册来源1pc 2android 3iso" prop="regFrom">
									<el-input v-model="form.regFrom" placeholder="请输入注册来源1pc 2android 3iso" clearable></el-input>
								</el-form-item>
								<el-form-item label="积分(剩余积分)" prop="integral">
									<el-input v-model="form.integral" placeholder="请输入积分(剩余积分)" clearable></el-input>
								</el-form-item>
								<el-form-item label="总积分" prop="integralCount">
									<el-input v-model="form.integralCount" placeholder="请输入总积分" clearable></el-input>
								</el-form-item>
								<el-form-item label="金币" prop="gold">
									<el-input v-model="form.gold" placeholder="请输入金币" clearable></el-input>
								</el-form-item>
								<el-form-item label="1锁定 0未锁定 登录超过次数" prop="locked">
									<el-input v-model="form.locked" placeholder="请输入1锁定 0未锁定 登录超过次数" clearable></el-input>
								</el-form-item>
								<el-form-item label="经度" prop="longitude">
									<el-input v-model="form.longitude" placeholder="请输入经度" clearable></el-input>
								</el-form-item>
								<el-form-item label="纬度" prop="latitude">
									<el-input v-model="form.latitude" placeholder="请输入纬度" clearable></el-input>
								</el-form-item>
								<el-form-item label="获取经纬度时间" prop="nearbyTime">
									<el-input v-model="form.nearbyTime" placeholder="请输入获取经纬度时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="语言编码" prop="language">
									<el-input v-model="form.language" placeholder="请输入语言编码" clearable></el-input>
								</el-form-item>
								<el-form-item label="生日" prop="birthday">
									<el-input v-model="form.birthday" placeholder="请输入生日" clearable></el-input>
								</el-form-item>
								<el-form-item label="1男 2女 3其他" prop="sex">
									<el-input v-model="form.sex" placeholder="请输入1男 2女 3其他" clearable></el-input>
								</el-form-item>
								<el-form-item label="头像地址" prop="headPortrait">
									<el-input v-model="form.headPortrait" placeholder="请输入头像地址" clearable></el-input>
								</el-form-item>
								<el-form-item label="手机品牌型号" prop="telVersion">
									<el-input v-model="form.telVersion" placeholder="请输入手机品牌型号" clearable></el-input>
								</el-form-item>
								<el-form-item label="推广员编码 谁推荐我安装的" prop="promoteNum">
									<el-input v-model="form.promoteNum" placeholder="请输入推广员编码 谁推荐我安装的" clearable></el-input>
								</el-form-item>
								<el-form-item label="微信openid 小程序" prop="wxOpenId">
									<el-input v-model="form.wxOpenId" placeholder="请输入微信openid 小程序" clearable></el-input>
								</el-form-item>
								<el-form-item label="公众号" prop="wxgzhOpenId">
									<el-input v-model="form.wxgzhOpenId" placeholder="请输入公众号" clearable></el-input>
								</el-form-item>
								<el-form-item label="单点登录标识" prop="unionid">
									<el-input v-model="form.unionid" placeholder="请输入单点登录标识" clearable></el-input>
								</el-form-item>
								<el-form-item label="水印签名图片" prop="qmImg">
									<el-input v-model="form.qmImg" placeholder="请输入水印签名图片" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import customerAPI from '@/api/customer/customer';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					customerId: "",
					departmentId: "",
					regionPath: "",
					membershipLevel: "",
					urlName: "",
					loginName: "",
					password: "",
					userName: "",
					telephone: "",
					address: "",
					email: "",
					status: "",
					lastInTime: "",
					createTime: "",
					lastPayTime: "",
					regFrom: "",
					integral: "",
					integralCount: "",
					gold: "",
					locked: "",
					longitude: "",
					latitude: "",
					nearbyTime: "",
					language: "",
					birthday: "",
					sex: "",
					headPortrait: "",
					telVersion: "",
					promoteNum: "",
					wxOpenId: "",
					wxgzhOpenId: "",
					unionid: "",
					qmImg: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await customerAPI.customer.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.customerId = data.customerId;
				this.form.departmentId = data.departmentId;
				this.form.regionPath = data.regionPath;
				this.form.membershipLevel = data.membershipLevel;
				this.form.urlName = data.urlName;
				this.form.loginName = data.loginName;
				this.form.password = data.password;
				this.form.userName = data.userName;
				this.form.telephone = data.telephone;
				this.form.address = data.address;
				this.form.email = data.email;
				this.form.status = data.status;
				this.form.lastInTime = data.lastInTime;
				this.form.createTime = data.createTime;
				this.form.lastPayTime = data.lastPayTime;
				this.form.regFrom = data.regFrom;
				this.form.integral = data.integral;
				this.form.integralCount = data.integralCount;
				this.form.gold = data.gold;
				this.form.locked = data.locked;
				this.form.longitude = data.longitude;
				this.form.latitude = data.latitude;
				this.form.nearbyTime = data.nearbyTime;
				this.form.language = data.language;
				this.form.birthday = data.birthday;
				this.form.sex = data.sex;
				this.form.headPortrait = data.headPortrait;
				this.form.telVersion = data.telVersion;
				this.form.promoteNum = data.promoteNum;
				this.form.wxOpenId = data.wxOpenId;
				this.form.wxgzhOpenId = data.wxgzhOpenId;
				this.form.unionid = data.unionid;
				this.form.qmImg = data.qmImg;
			}
		}
	}
</script>
<style>
</style>
